package web;

import com.alibaba.fastjson.JSON;
import service.brandService.brandService;
import service.brandServiceImpl.brandServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;

@WebServlet("/deleteByIdsServlet")
public class deleteByIdsServlet extends HttpServlet {
    private brandService brandservice=new brandServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        BufferedReader br = req.getReader();//获取请求体数据（id数组）
        String s = br.readLine();
        int[] ids = JSON.parseObject(s, int[].class);//转化为数组
        brandservice.deleteByIds(ids);//调用方法进行批量删除
        resp.getWriter().write("yes");//删除成功后返回yes
    }
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }
}
